package com.yt.demo.service.feign.fallback;

import com.yt.demo.dto.BaseReq;
import com.yt.demo.dto.BaseResp;
import com.yt.demo.service.feign.FeignHelloService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Component
public class FeignHelloServiceHystrix implements FallbackFactory<FeignHelloService> {

    @Override
    public FeignHelloService create(Throwable cause) {
        log.error("feign调用helloController报错", cause);
        return new FeignHelloService() {
            @Override
            public BaseResp<String> testGet(String param) {
                return BaseResp.error(param);
            }

            @Override
            public BaseResp<String> testPost(BaseReq<String> req) {
                return BaseResp.error(req.getParam());
            }

            @Override
            public BaseResp<String> testFile(MultipartFile file) {
                return BaseResp.error(file.getOriginalFilename());
            }
        };
    }
}
